public class Solution {
    public int getMaxLen(int[] nums) {
        int len = nums.length;

        int[] f = new int[len + 1];//正
        int[] g = new int[len + 1];//负

        for (int i = 1; i < len + 1; i++) {
            if (nums[i - 1] > 0) {
                f[i] = f[i - 1] + 1;
                g[i] = g[i - 1] == 0 ? 0 : g[i - 1] + 1;
            } else if (nums[i - 1] < 0) {
                f[i] = g[i - 1] == 0 ? 0 : g[i - 1] + 1;
                g[i] = f[i - 1] + 1;
            } else {
                f[i] = 0;
                g[i] = 0;
            }
        }

        int ret = 0;

        for (int num : f) {
            ret = Math.max(ret, num);
        }

        return ret;
    }
}
